/*
 * @Author: zeki mini
 * @Date: 2020-12-18 14:08:49
 * @LastEditors: 汪滔
 * @LastEditTime: 2021-06-03 09:31:10
 * @Description: 合同列表item
 */

import React from 'react';
import { StyleSheet, TouchableOpacity, View, Text, Image } from 'react-native';
import moment from 'moment';
import { px2dp, mainBgColorWhite, fontColorSecDeepGray, fontColorDeepGray, fontColorRed } from '@/styles';
import { iconPdfGray } from '@/images';

export default class ListItem extends React.PureComponent {
  render() {
    const { detail, onClick } = this.props;
    const { contractName, contractNo, createTime, contractStatus } = detail;
    let contractStatusText = '';
    if (contractStatus === 2) {
      contractStatusText = '待签署';
    }
    if (contractStatus === 3) {
      contractStatusText = '已签署';
    }
    return (
      <TouchableOpacity style={styles.container} activeOpacity={0.8} onPress={() => onClick(detail)}>
        <View style={styles.left}>
          <Image
            source={iconPdfGray}
            style={styles.pdfImg}
            resizeMode='contain'
          />
          <View style={styles.textWrap}>
            <Text style={styles.title}>{contractName}</Text>
            <Text style={styles.code}>{contractNo}</Text>
            <Text style={styles.code}>
              创建时间：
              {moment(createTime).format('YYYY-MM-DD')}
            </Text>
          </View>
        </View>
        <View style={styles.right}>
          <Text style={[styles.rightLabel, contractStatus === 2 && { color: fontColorRed }]}>{contractStatusText}</Text>
        </View>
      </TouchableOpacity>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    width: px2dp(702),
    height: px2dp(183),
    borderRadius: px2dp(16),
    backgroundColor: mainBgColorWhite,
    marginTop: px2dp(24),
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    paddingHorizontal: px2dp(24)
  },
  left: {
    flexDirection: 'row',
    alignItems: 'center',

  },
  textWrap: {
    marginLeft: px2dp(24)
  },
  pdfImg: {
    width: px2dp(73),
    height: px2dp(86)
  },
  title: {
    fontSize: px2dp(32),
    fontWeight: 'bold'
  },
  code: {
    fontSize: px2dp(26),
    color: fontColorSecDeepGray
  },
  rightLabel: {
    fontSize: px2dp(32),
    color: fontColorDeepGray
  },
});
